//
//  HNSH_RewardPoolManager.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/3.
//

#import "HNSH_RewardPoolManager.h"

//view
#import "JXPagerView.h"
#import "JXCategoryTitleView.h"
#import "JXCategoryIndicatorLineView.h"

#import "HNSH_RewardPoolHeaderView.h"

#import "HNSH_RewardPoolViewController.h"

static const CGFloat JXTableHeaderViewHeight = 243;
static const CGFloat JXheightForHeaderInSection = 44;

@interface HNSH_RewardPoolManager ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, JXCategoryViewDelegate>
/**  */
@property (nonatomic, strong) JXPagerView * pagerView;
/**  */
@property (nonatomic, strong) JXCategoryTitleView * categoryView;
/**  */
@property (nonatomic, strong) HNSH_RewardPoolHeaderView * headerView;

@end

@implementation HNSH_RewardPoolManager

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
        
    [self showNavTitle:@"奖励池" showLeftItem:YES];
    self.navView.titleLabel.textColor = [UIColor appWhiteLabelColor];
    self.navView.backgroundColor = [UIColor clearColor];
    [self addCategoryView];
    
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kNavBarAndStatusBarHeight+225)];
    imgV.image = [UIImage imageNamed:@"mine_bill_jlc_top_bg"];
    [self.view addSubview:imgV];
    [self.view sendSubviewToBack:imgV];
    
//    [self.view addSubview:self.headerView];
        
    [self loadNewData];
    
    [self addAllViews];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if (_pagerView) {
        [_pagerView reloadData];
    }
}

- (void)addAllViews{
    [self.view addSubview:self.pagerView];
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];

    self.pagerView.frame = CGRectMake(20, kNavBarAndStatusBarHeight, kScreenWidth-40, kScreenHeight - kNavBarAndStatusBarHeight);
}

//MARK: 获取所有代币
- (void)addCategoryView{
    self.categoryView.titles = @[@"业绩前十奖励", @"平级奖励"];
    [self.categoryView reloadDataWithoutListContainer];
    [self.pagerView reloadData];
    [self.view clipCornerWithView:self.categoryView cornerWidth:12 cornerType:UIRectCornerTopLeft|UIRectCornerTopRight];
}

- (void)loadNewData{
    [HNSH_UserNetServer requestBillStatisticsWithType:[NSString stringWithFormat:@"%ld",1] success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            self.headerView.dic = responseObject.resultset;
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: Getter Methods
- (JXPagerView *)pagerView{
    if (!_pagerView) {
        _pagerView = [[JXPagerView alloc] initWithDelegate:self];
        _pagerView.mainTableView.gestureDelegate = self;
        _pagerView.mainTableView.backgroundColor = [UIColor clearColor];
        _pagerView.backgroundColor = [UIColor clearColor];
    }
    return _pagerView;
}

- (HNSH_RewardPoolHeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HNSH_RewardPoolHeaderView alloc] initWithFrame:CGRectMake(20, 0, kScreenWidth-40, JXTableHeaderViewHeight)];
    }
    return _headerView;
}

- (JXCategoryTitleView *)categoryView{
    if (!_categoryView) {
        _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(16, 0, kScreenWidth-32, JXheightForHeaderInSection)];
        _categoryView.backgroundColor = [UIColor whiteColor];
        _categoryView.delegate = self;
        _categoryView.titleSelectedColor = [UIColor appGreenColor];
        _categoryView.titleColor = [UIColor colorWithHexString:@"#999999"];
        _categoryView.titleFont = [UIFont boldSystemFontOfSize:16];
        _categoryView.titleSelectedFont = [UIFont boldSystemFontOfSize:16];
        _categoryView.titleColorGradientEnabled = YES;
        _categoryView.titleLabelZoomEnabled = YES;
        _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
        _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;

        JXCategoryIndicatorLineView * lineView = [JXCategoryIndicatorLineView new];
        lineView.indicatorColor = [UIColor appGreenColor];
        lineView.indicatorWidth = 32;
        _categoryView.indicators = @[lineView];
    }
    return _categoryView;
}

//MARK: JXPagerViewDelegate Methods
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView{
    return self.headerView;
}

- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView{
    return JXTableHeaderViewHeight;
}

- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView{
    return JXheightForHeaderInSection;
}

- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView{
    return self.categoryView;
}

- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView{
    //和categoryView的item数量一致
    return self.categoryView.titles.count;
}

- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index{
    HNSH_RewardPoolViewController * list = [HNSH_RewardPoolViewController new];
    list.type = index;
    return list;
}

//MARK: JXCategoryViewDelegate Methods
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
    
}

//MARK: JXPagerMainTableViewGestureDelegate Methods
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    //禁止categoryView左右滑动的时候，上下和左右都可以滚动
    if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
        return NO;
    }
    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}


@end
